package danceDoll;

import com.jme3.asset.AssetManager;
import com.jme3.light.PointLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Node;
/**
 * Creates the Scenery, Loads the model and creates lights.
 * @author master
 * @version 1.0
 * @date 22.03.2012
 */
public class Scenery extends DanceDoll {

    private Node root;
    private Model m;

    public Scenery(AssetManager assetManager) {
        root = new Node("root");
        this.assetManager = assetManager;
        
        root.attachChild(drawScenery());
    }

    /**
     * Creates the Scenery and retuns it.
     * @return Node with the Scenery
     */
    private Node drawScenery() {
        Node mainNode = new Node("mainNode");

        Node disco = new Node("disco");
        disco = (Node) assetManager.loadModel("Scenes/Disco/disco.j3o");
        mainNode.attachChild(disco);
        disco.setLocalScale(1.5f);
        disco.setLocalRotation(new Quaternion(new float[]{0, (-90 * FastMath.DEG_TO_RAD), 0}));
        //disco.setShadowMode(ShadowMode.CastAndReceive);
          
        Node turntable = new Node("turntable");
        
        // Scheibe erstellen               
        Node record = new Node("record");
        record = (Node) assetManager.loadModel("Scenes/Disco/record.j3o");
        turntable.attachChild(record);
        record.setLocalTranslation(0f, -0.8f, 0f);
        record.setShadowMode(ShadowMode.CastAndReceive);
        
        Node mirrorball = new Node("mirrorball");
        mirrorball = (Node) assetManager.loadModel("Scenes/Disco/mirrorball.j3o");
        turntable.attachChild(mirrorball);
        mirrorball.setLocalScale(0.2f);
        mirrorball.setLocalTranslation(0f, 12f, 0f);

        // Knoten für die Puppe erstellen
        Node danceDoll = new Node("danceDoll");

        m = new Model(assetManager);
        danceDoll.attachChild(m.getModel());

        turntable.attachChild(danceDoll);
        danceDoll.setShadowMode(ShadowMode.CastAndReceive);
              
        // Punktlicht hinzufügen
        PointLight bulb = new PointLight();
        bulb.setColor(ColorRGBA.White);
        bulb.setRadius(40f);
        bulb.setPosition(new Vector3f(0f, 5f, 10f));
        mainNode.addLight(bulb);
        

        mainNode.attachChild(turntable);
        
        return mainNode;
    }
    
    /**
     * Returns the Model-Node, loaded in Scenery
     * @return Node with the Model
     */
    public Model getModel() {
        return m;
    }

    /**
     * Returns the Node all Scenery was created in
     * @return Node from the Scenery
     */
    public Node getNode() {
        return root;
    }
}
